﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;

namespace Skynet.WebAdministracion.Views.ExamReview
{
    public class ExamReviewPresenter : Infrastructure.Web.Views.Master.MasterPresenter<IExamReview>
    {
        [Dependency]
        public WebFoundation.Services.Session.ISessionService SessionService { get; set; }

        [Dependency]
        public WebFoundation.Services.Navigation.INavigationService NavigationService { get; set; }


        [Dependency]
        public BusinessLogic.BusinessComponents.IBCExams BCExamenes { get; set; }
        public override void OnViewInitialized()
        {
            base.OnViewInitialized();

        }
        public override void OnViewLoaded()
        {
            var question = this.SessionService.RuntimeExamQuestions;
            List<object> items = new List<object>();
            var count = 0;
            foreach (var item in question)
            {
                count = count + 1;
                items.Add(new { Id=item.CustomerQuestionId , Number=count, Review = item.Review});                
            }
            this.View.Questions = items;
        }

        public void ShowQuestion(Guid key)
        {
            var questions = this.SessionService.RuntimeExamQuestions;
            var index = 0;
            for (int i = 0; i < questions.Count; i++)
			{
                if ( questions.ElementAt(i).CustomerQuestionId==key)
                {
                    break;        
                }
                index+=1;
			}
            this.SessionService.RuntimeExamQuestionPosition = index;
            this.NavigationService.Navigate("~/Evaluation/ExamViewer.aspx");
        }

        public void EndExam()
        {
            var examid  = this.SessionService.RuntimeExamByCustomerId;
            this.BCExamenes.FinishExam(examid);
            this.NavigationService.Navigate("~/Evaluation/ExamEndViewer.aspx");
        }
    }
}
